package org.example.Spring.Bean;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Repository;

//使用@Repository注解将UserDaolmpl类标识为spring中的Bean
//括号里的是该Bean的名字
@Repository("userDao")       //指定一个数据访问组件Bean，用于将数据访问层的类标识为spring中的Bean，功能同@Component
public class UserDaolmpl implements UserDao{

    @Override
    public void save() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        User user = (User) applicationContext.getBean("user");
        System.out.println(user);
        System.out.println("执行UserDaolmpl.save()");
    }
}
